﻿<%@ Page Language="C#" Inherits="Dimok.Web.UI.PageToPDF" %>
<%@ Register Src="~/Manager/Documents/BayQuest/Letters/Controls/WelcomeLetter.ascx" TagPrefix="UI" TagName="BayQyest_WelcomeLetter" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
	public override string FileName { get { return "WL_" + LoanID; } }
	int LoanID { get { return int.Parse("0" + Request["ApplID"]); } }
	string LoanIDs { get { return Request["LoanIDs"] + ""; } }
	int CompanyID { get { return int.Parse("0" + Request["CompanyID"]); } }
	string Filter { get { return Request["Filter"] + ""; } }
	string Letter { get { return Request["Letter"] + ""; } }
	protected override void OnInit(EventArgs e) {
		base.OnInit(e);
		rptLetters.ItemCreated += new RepeaterItemEventHandler(rptLetters_ItemCreated);
		dsExport.FilterDefault = Filter;
	}

	void rptLetters_ItemCreated(object sender, RepeaterItemEventArgs e) {
		DataRowView row = (DataRowView)e.Item.DataItem;
		if (row["ApplID"] == DBNull.Value) {
			Response.Clear();
			Response.Write("<pre>Account " + row["UsixID"] + " does not have a LoanID.</pre>");
			Response.End();
		}
		e.Item.Controls.AddAt(0, DrawLetter((int)row["ApplID"], Convert.ToInt32(row["CompanyID"])));
	}
	Control DrawLetter(int LoanID,int CompanyID){
		string controlPath = ConfigurationSettings.AppSettings[Letter + ".Path"];// ApplicationSettingsBase "~/Manager/Documents/BayQuest/Letters/Controls/WelcomeLetter.ascx";
		controlPath += ConfigurationSettings.AppSettings[Letter + "." + new USIXExportDataSource().SelectEx(LoanID)[0]["CompanyID"] + ".Path"];
		controlPath += ConfigurationSettings.AppSettings[Letter + "WelcomeLetter.Name"];
		Control c = LoadControl(controlPath);
		System.Reflection.PropertyInfo pi = c.GetType().GetProperty("LoanID");
		if (pi == null) throw new NotImplementedException("LoanID property is not implemented in " + controlPath);
		pi.SetValue(c, LoanID,new object[]{});
		return c;
	}
	protected override void OnLoad(EventArgs e) {
		base.OnLoad(e);
	}
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style>
 p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin:0in;
	margin-bottom:.0001pt;
	text-align:justify;
	font-size:12.0pt;
	font-family:"Times New Roman","serif";}
h1{	font-size:16.0pt;}
h1,h2,h3,h4,h5,h6
{
	margin:0in;
	margin-bottom:.0001pt;
	text-align:center;
	page-break-after:avoid;
	font-family:"Century","serif";}
h5
{
	font-size:14.0pt;
	font-family:"Times New Roman","serif";
	font-weight:normal;}
h6
{
	font-size:12.0pt;
	font-family:"Times New Roman","serif";}
p.MsoTitle, li.MsoTitle, div.MsoTitle
	{margin:0in;
	margin-bottom:.0001pt;
	text-align:center;
	font-size:20.0pt;
	font-family:"Century","serif";
	font-weight:bold;}
p.MsoBodyText, li.MsoBodyText, div.MsoBodyText
	{margin:0in;
	margin-bottom:.0001pt;
	text-align:justify;
	font-size:14.0pt;
	font-family:"Times New Roman","serif";}
p.MsoSubtitle, li.MsoSubtitle, div.MsoSubtitle
	{margin:0in;
	margin-bottom:.0001pt;
	text-align:center;
	font-size:16.0pt;
	font-family:"Century","serif";
	font-weight:bold;}
@page Section1
{size:8.5in 11.0in;
margin: 1in 1in 1in 1in;
border:double windowtext 4.5pt;
padding:24.0pt 24.0pt 24.0pt 24.0pt;}
div.Section1{
width:85%;
page:Section1;}
</style>
</head>
<body>
<form id="form1" runat="server">
<asp:Repeater ID="rptLetters" DataSourceID="dsExport" runat="server"><ItemTemplate>
<div style="page-break-after:always">&nbsp;</div>
</ItemTemplate></asp:Repeater>
</form>
<DS:USIXExportDataSource ID="dsExport" EmtyRowPolicy="None" runat="server">
</DS:USIXExportDataSource>
</body>
</html>
